﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Web.UI.WebControls;
using System.Web.UI;

namespace Acms.AcmsControls.ContentControls.Admin
{
    public class FlashAdminDisplay : BaseAdminDisplay<FlashContentControlProperties>
    {
        protected override string GetCssClass
        {
            get { return "flash"; }
        }

        public override void PropertiesLoaded(FlashContentControlProperties properties)
        {
            if (properties != null)
            {
                flash.FlashFileUrl = RenderFile.GetUrl(properties.ResourceId, Page);
                flash.Width = properties.Width > 500 ? 500 : properties.Width;
                flash.Height = properties.Height > 500 ? 500 : properties.Height;
                flash.MinVersion = properties.MinVersion;
                dimentions.Text = string.Format("{0}px x {1}px", properties.Width, properties.Height);
                minVersion.Text = properties.MinVersion;
            }
        }


        Acms.WebControls.FlashControl flash = new Acms.WebControls.FlashControl();
        Label dimentions = new Label();
        Label minVersion = new Label();

        protected override void CreateChildControls()
        {
            flash.WMode = Acms.WebControls.FlashControl.WModes.Transparent;
            this.Controls.Add(flash);
            this.Controls.Add(dimentions);
            this.Controls.Add(minVersion);
            base.CreateChildControls();
        }

        protected override void RenderContents(HtmlTextWriter writer)
        {
            if (!string.IsNullOrEmpty(flash.FlashFileUrl))
            {
                flash.RenderControl(writer);

                writer.AddAttribute(HtmlTextWriterAttribute.Class, "form");
                writer.RenderBeginTag(HtmlTextWriterTag.Ul);

                writer.RenderBeginTag(HtmlTextWriterTag.Li);

                writer.AddAttribute(HtmlTextWriterAttribute.For, string.Concat(this.ClientID, minVersion.ClientID));
                writer.RenderBeginTag(HtmlTextWriterTag.Label);
                writer.Write("Min Version:");
                writer.RenderEndTag();//label

                minVersion.RenderControl(writer);

                writer.RenderEndTag();//li

                writer.RenderBeginTag(HtmlTextWriterTag.Li);

                writer.AddAttribute(HtmlTextWriterAttribute.For, string.Concat(this.ClientID, dimentions.ClientID));
                writer.RenderBeginTag(HtmlTextWriterTag.Label);
                writer.Write("Dimensions:");
                writer.RenderEndTag();//lable

                dimentions.RenderControl(writer);

                writer.RenderEndTag();//li

                writer.RenderEndTag();//ul
            }
            else
            {
                writer.Write("No flash file has been uploaded");
            }
        }
    }
}
